package com.etc.controller;

import com.etc.entity.Collections;

import com.etc.entity.CollectionsJudge;
import com.etc.service.CollectionsService;
import com.etc.util.PageData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;


@Controller
@RequestMapping("colapi")
public class CollectionsController {

    @Resource(name="collectionService")
    private CollectionsService collectionsService;

    /**
     * 个人收藏列表展示
     * @param page
     * @param limit
     * @param content
     * @return
     */
    @RequestMapping(value = "collection" ,method = RequestMethod.GET)
    @ResponseBody
    public  PageData<Collections>  selectCollectionByPage(int page, int limit, String content, HttpServletRequest request){
        if (content == null) {
            content = "";
        }
        PageData<Collections> pd= collectionsService.selectCollectionByPage(page, limit, content);
        pd.setCode(0);
        pd.setMsg("");
        request.getSession().setAttribute( "pd",pd);
        return  pd;

    }




    /**
     * 更新收藏操作
     * @collectionsJudgec collectionsJudgec
     * @return
     */
    @RequestMapping(value = "updatecollection" ,method = RequestMethod.POST)
    @ResponseBody
    public HashMap insertCollection( CollectionsJudge collectionsJudgec){


        HashMap result=collectionsService.updateCollections(collectionsJudgec.getuId(),collectionsJudgec.gettId());
        return result;


    }


}
